home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / fileLoad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-13  |  2.6 KB  |  112 lines

  1. /* 
  2.  * fileLoad.c --
  3.  *
  4.  *    The routine to load a program into main memory.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  */
  9.  
  10. #ifdef notdef
  11. static char rcsid[] = "$Header: /sprite/src/boot/scsiDiskBoot/RCS/fileLoad.c,v 1.7 89/01/06 08:14:27 brent Exp $ SPRITE (Berkeley)";
  12. #endif not lint
  13.  
  14. #include "sprite.h"
  15. #include "fs.h"
  16. #include "procAOUT.h"
  17. #include "machMon.h"
  18. #include "boot.h"
  19.  
  20. #define KERNEL_ENTRY 0x4000
  21.  
  22.  
  23. /*
  24.  *----------------------------------------------------------------------
  25.  *
  26.  * FileLoad --
  27.  *
  28.  *    Read in the kernel object file.  This is loaded into memory at
  29.  *    a pre-defined location (in spite of what is in the a.out header)
  30.  *    for compatibility with Sun/UNIX boot programs.  The Sprite kernel
  31.  *    expects to be loaded into the wrong place and does some re-mapping
  32.  *    to relocate the kernel into high virtual memory.
  33.  *
  34.  * Results:
  35.  *    The entry point.
  36.  *
  37.  * Side effects:
  38.  *    None.
  39.  *
  40.  *----------------------------------------------------------------------
  41.  */
  42.  
  43.  
  44. int
  45. FileLoad(handlePtr)
  46.     register FsHandleHeader    *handlePtr;
  47. {
  48.     Proc_AOUT        aout;
  49.     int            bytesRead;
  50.     register int    *addr;
  51.     register ReturnStatus status;
  52.     register int    i;
  53.     register int    numBytes;
  54.  
  55.     /*
  56.      * Read a.out header.
  57.      */
  58.  
  59.     status = Fs_Read(handlePtr, 0, sizeof(aout), &aout, &bytesRead);
  60.     if (status != SUCCESS || bytesRead != sizeof(aout)) {
  61.     Mach_MonPrintf("No a.out header");
  62.     goto readError;
  63.     } else if (aout.magic != PROC_OMAGIC) {
  64.     Mach_MonPrintf("A.out? mag %x size %d+%d+%d\n",
  65.         aout.magic, aout.code, aout.data, aout.bss);
  66.     return(-1);
  67.     }
  68.  
  69.     /*
  70.      * Read the code.
  71.      */
  72.  
  73.     numBytes = aout.code;
  74.     Mach_MonPrintf("Size: %d", numBytes);
  75.     status = Fs_Read(handlePtr, PROC_CODE_FILE_OFFSET(aout), numBytes,
  76.               KERNEL_ENTRY, &bytesRead);
  77.     if (status != SUCCESS) {
  78.     goto readError;
  79.     } else if (bytesRead != numBytes) {
  80.     goto shortRead;
  81.     }
  82.  
  83.     /*
  84.      * Read the initialized data.
  85.      */
  86.  
  87.     numBytes = aout.data;
  88.     Mach_MonPrintf("+%d", numBytes);
  89.     status = Fs_Read(handlePtr, PROC_DATA_FILE_OFFSET(aout), numBytes,
  90.               KERNEL_ENTRY + aout.code, &bytesRead);
  91.     if (status != SUCCESS) {
  92. readError:
  93.     Mach_MonPrintf("\nRead error <%x>\n", status);
  94.     return(-1);
  95.     } else if (bytesRead != numBytes) {
  96. shortRead:
  97.     Mach_MonPrintf("\nShort read (%d)\n", bytesRead);
  98.     return(-1);
  99.     }
  100.  
  101.     /*
  102.      * Zero out the bss.
  103.      */
  104.  
  105.     numBytes = aout.bss;
  106.     Mach_MonPrintf("+%d\n", numBytes);
  107.     addr = (int *) (KERNEL_ENTRY + aout.code + aout.data);
  108.     bzero(addr, numBytes);
  109.  
  110.     return (KERNEL_ENTRY);
  111. }
  112.